   <%@ include  file="Header.jsp" %>   
<jsp:directive.page import="java.sql.*"/>
<jsp:directive.page import="Connectivity.ConnectionManager"/>
<jsp:directive.page import="java.util.Date"/>
<jsp:directive.page import="com.sun.corba.se.spi.orbutil.fsm.Guard.Result"/>
 <%

String status = request.getParameter("status")!=null?request.getParameter("status"):"BACK";
String name = request.getParameter("name")!=null?request.getParameter("name"):"null";
String branch = request.getParameter("branch")!=null?request.getParameter("branch"):"null";
String submit = request.getParameter("submit")!=null?request.getParameter("submit"):"null";
String cust_id = request.getParameter("cust_id")!=null?request.getParameter("cust_id"):"0"; 
String objname = request.getParameter("objname")!=null?request.getParameter("objname"):""; 

String firmshort=""+(session.getAttribute("firm_short"));
%>
   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
   "http://www.w3.org/TR/html4/loose.dtd">

   <html>
  <base href="<%=basePath%>">
      <head>
         <meta http-equiv="Content-Type" 
            content="text/html; charset=windows-1256">
         <title>   Customer Registration  </title>
      </head>
 <SCRIPT language=JavaScript>

function callDegree(obj)
{
		if(obj.selectedIndex=='0'){
			alert('Please Select '+obj);
		}
		 if(obj.name=='name')
		 {insertParam("name",(obj.value));}
		 if(obj.name=='branch')
		 {

		 var name=document.callentry.name.value;
		 insertParam("cust_id",(obj.value));
		
		 }
	
 
			//document.callentry.action = "";
			//document.callentry.submit();
} 


function groupcheck(obj)
{
var value=document.callentry.obj.value;
	alert("value:"+value);
		
 


}
function insertParam(key, value) 
{    
	key = escape(key); value = escape(value);
    var kvp = document.location.search.substr(1).split('&');
 	if (kvp == '') 
 	{
 	document.location.search = '?' + key + '=' + value;
 	}
 	else 
 	{
 	var i = kvp.length; var x; while (i--) 
 	{
 	  x = kvp[i].split('='); 
 	if (x[0] == key) 
  {
   x[1] = value;
   kvp[i] = x.join('=');
   break;
  }
  }
  if (i < 0) 
  { kvp[kvp.length] = [key, value].join('='); }
        //this will reload the page, it's likely better to store this until finished 
    document.location.search = kvp.join('&');         
  }
} 




function displayRow(obj)
 {
 var value=obj.value;
 var temp = new Array();
 temp = value.split('$');
 var group_id=temp[0];
 var group_name=temp[1];
 var objname="problem"+group_id;
//alert("url:"+(document.location.href));
//alert("url:"+(document.location.href));
 
//var url =(document.location.href)+'&objname='+objname)"; 
	if(obj.checked && (obj.name)==(objname))
	{
	 //insertParam("objname",(objname));
	 document.getElementById(""+group_id).style.display="block";

		
 
	}
	
	
	
	
 }
	
 function hideRow(){
		if(document.callentry.oldAddmission && document.callentry.oldAddmission[0].checked)
		{
			glbOldAdmission = 'Y';
			document.getElementById("hiddenRow").style.display="block";
		}
		else
		{
			glbOldAdmission = 'N';
			document.getElementById("hiddenRow").style.display="none";
		}
	}




	
  </SCRIPT>
   
   
<body bgcolor="white" >


 <table border=1 width=80% height=100%>
 
<form name=callentry method=get action="/Genius/CustomerEntry"  >
    <table align=center border=1  width=80% >
   
    <%


    if(status.equalsIgnoreCase("I"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> INSERTED SUCCESSFULLY </font> </td></tr>");
    }
     if(status.equalsIgnoreCase("U"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> UPDATED SUCCESSFULLY </font> </td></tr>");
    }
     if(status.equalsIgnoreCase("D"))
    {
    out.println("  <tr><td align=center width=100% colspan=10><font size=4 color=black> DELETED SUCCESSFULLY </font> </td></tr>");
    }
     Date d1=new Date();
    String currentdate=(d1.getDate()+"-"+(d1.getMonth()+1)+"-"+(d1.getYear()+1900));
     String currentdate1=((d1.getYear()+1900)+"-"+(d1.getMonth()+1)+"-"+(d1.getDate()));
    String complaintID=firmshort+""+(d1.getDate()+""+(d1.getMonth()+1)+""+(d1.getYear()+1900));
    String currenttime=((d1.getHours())+":"+d1.getMinutes()+":"+d1.getSeconds());
    String branchno="";
    int registerno=0 ; 
    if(cust_id!="0")
    {
    String countregq="select count(distinct complaint_id) from callentry where customer_id="+cust_id+" and status='V'";
    PreparedStatement prstcount= con.prepareStatement(countregq);
    ResultSet countrs=prstcount.executeQuery();
    while(countrs.next())
    {registerno=Integer.parseInt(""+countrs.getString(1));}
    
    } 
     
     %>
     

    <tr><td align=center   colspan=10><font size=4 color=Blue> CALL ENTRY  </font> </td></tr>
 <!-- --------Date time and compalintId----------------- -->
   
    <tr>
  	<td align=center   colspan=10>
	<table border=1 style="width:600px">
		<tr>
		<td style="width:150px"><font size=2>DATE&nbsp;:&nbsp;<%=currentdate%></font> </td>
		<td style="width:150px"><font size=2>TIME&nbsp;:&nbsp; <%=currenttime%></font></td>
		<td style="width:200px"><font size=2>COMPLAINT ID&nbsp;:&nbsp;<%=cust_id%>:<%=(registerno+ 1)%><%=complaintID%></font></td>
		</tr>
	</table>
	</td>
    </tr>
    
       
    
    
<!-- -Name selection -->  
<tr>
   	<td align=left colspan=5 >NAME:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   	<td align=left colspan=5>
 	<select name="name"  onChange="callDegree(this);"  >
 	<option value="0">--Select--</option>
 	<%
 	String	custquerry="select distinct customer_name";
 	custquerry=custquerry+" from customer_master where  status='V' order by customer_name";
   	prst1=con.prepareStatement(""+custquerry);
  	ResultSet rs1=prst1.executeQuery();
  	while(rs1.next())
  	{ 
       if((name).equalsIgnoreCase(rs1.getString(1)))  	
  		{%><option value="<%=rs1.getString(1)%>" selected><%=rs1.getString(1)%></option>
 	<%}else{ %>
 	<option value="<%=rs1.getString(1)%>"><%=rs1.getString(1)%></option>
 	<%}} %>
 	</select>
 	</td>
</tr>
<!-- -end of name selection -->



   <!-- -Branch selection -->
   <tr>
   	<td align=left colspan=5 > BRANCH/AREA:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   	<td align=left  colspan=5> <select name="branch"  onChange="callDegree(this);"  >
 	<option value="0">--Select--</option>
 	<%
 	String	custquerry1="select customer_id,area";
 	custquerry1=custquerry1+" from customer_master where  status='V' ";
 	if(name!=(""))
 	{ custquerry1=custquerry1+" and customer_name='"+name+"'"; }
 	custquerry1=custquerry1+" order by area,customer_id";
 
    prst1=con.prepareStatement(""+custquerry1);
    ResultSet rs111=prst1.executeQuery();
 	while(rs111.next())
   { 
  	if(cust_id!="0" && cust_id.equalsIgnoreCase(rs111.getString(1)))
  	 {
  	 %><option selected value="<%=rs111.getString(1)%>" ><%=rs111.getString(2)%></option>
  	 <% }else{%>
  	  <option value="<%=rs111.getString(1)%>" ><%=rs111.getString(2)%></option>	  	 
 	 <%}}%>
 	</select>
 	</td>
   </tr>
 

   
    <tr>
    	<td align=left colspan=5 > PROBLEM WITH:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   		<td align=left  colspan=5> 
 		 <table border=1 width=100%>
    	 
 		<%
 		int groupcount=0;
 		rs1=null;
 		String	groupquery="select group_id,group_name";
 		groupquery=groupquery+" from item_group_master where  status='V'";
   		prst1=con.prepareStatement(""+groupquery);
	    rs1=prst1.executeQuery();
 		while(rs1.next())
 		{groupcount++;
 		%>
     	<TR>
		<td align=left colspan=5 >
		<%if(objname.equalsIgnoreCase("problem"+rs1.getString(1)))
		{objname=objname+("problem"+rs1.getString(1));
			%>
		<INPUT onclick=displayRow(this) checked value="<%=rs1.getString(1)+'$'+rs1.getString(2) %>" type=radio name=problem<%=rs1.getString(1)%>>
		<font size=2><%=rs1.getString(2)%></font>
		<%}else {%>
		<INPUT onclick=displayRow(this) value="<%=rs1.getString(1)+'$'+rs1.getString(2) %>" type=radio name=problem<%=rs1.getString(1)%>>
		<font size=2><%=rs1.getString(2)%></font>
		<%} %>
		 &nbsp;&nbsp;&nbsp;</td>

    	 
    	<td style="DISPLAY: none" id=<%=rs1.getString(1)%>>
    	
    	<SELECT  style="WIDTH:150px" name=<%=rs1.getString(2)%>> 
    	<OPTION selected value=0>--Select--</OPTION> 
   				 
 		<%
 		String	itemquery="select item_id,item_name";
 		itemquery=itemquery+" from item_master where  status='V' and group_id="+rs1.getString(1)+" order by item_name";
   		prst1=con.prepareStatement(""+itemquery);
	    ResultSet itemgroup=prst1.executeQuery();
	    int cnt=0;
 		while(itemgroup.next())
  		{ 
  		%>
  		<option onclick=displayRow(this) value="<%=itemgroup.getString(1)+'$'+itemgroup.getString(2) %>" ><%=itemgroup.getString(2)%>
		</option>
  		
 		<% 	}%>
 		<option onclick=displayRow(this) value="textfield" >OTHER
		</option>
 		</SELECT>
 		
 		
 		
 		
 	 	</td> 
 		 
  </tr>
  <%} %>
   
   </td>
 		</tr>
 		</table>
   
   
   
   
   
   
   
   <%=objname %>
   
   <tr>
    	<td align=left colspan=5 > NATURE OF FAULT:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   		<td align=left  colspan=5> 	
   		<table border=1 width=100%>
   		<tr>
   		<td>
   		<input type=text name=callfault1 style="width:400px">
		</td>	
 		 </tr>
 		 <tr>
 		 <td>
   		<input type=text name=callfault2 style="width:400px">
   		</td>
   		 </tr>
 		 </table>
 		 </td>
  </tr>
  
   <tr>
    	<td align=left colspan=5 > NATURE OF CALL:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   		<td align=left  colspan=5> 	
   		 <select name=callnature style="width:150px">
   		 <option value="0">---SELECT---</option>  
   		<%
   		prst=null;
   		String nquery="select call_nature_id,name from call_nature where status='V'";
   		prst=con.prepareStatement(nquery);
   		ResultSet nrs=prst.executeQuery();
   		while(nrs.next())
   		{
   		 %>
   		<option value="<%=nrs.getString(1)%>"><%=nrs.getString(2)%></option>  		 
   		<%} %>
   		 </select>	
   		 
   		    		    		 
 		 </td>
  </tr>
  
  
   <tr>
    	<td align=left colspan=5 > CALL LOCKED BY:&nbsp;&nbsp;&nbsp;<FONT color=red>*</FONT></td>
   		<td align=left  colspan=5> 	
   		<table border=1 width=100%>
   		<tr>
   		<td coslpan=1><font size=2>NAME :</font>  </td>	
   		 <td><input type=text name=calllockedby style="width:200px"></td>	
 		 </tr>
 		<tr>
   		<td coslpan=1><font size=2> CONTACT NO:</font>  </td>	
   		<td><input type=text name=calllockedcontact style="width:200px"></td>	
 		 </tr>
 		 </table>
 		 </td>
  </tr>
  
  <tr>
    	<td align=left colspan=5 > MATERIAL INWARD:&nbsp;&nbsp;&nbsp;<FONT color=red></FONT></td>
    	<td align=left colspan=5 ><input type=text name=minward style="width:400px"></td>	
   </tr>

 <tr>
    	<td align=left colspan=5 > MATERIAL OUTWARD:&nbsp;&nbsp;&nbsp;<FONT color=red></FONT></td>
    	<td align=left colspan=5 ><input type=text name=moutward style="width:400px"></td>	
   </tr>


    <tr><td align=right  colspan=5 ><input type=submit name=submit value="Create"   >
 &nbsp;&nbsp;&nbsp;&nbsp;</td><td align=left  colspan=5><input type=reset name=reset value="Reset"> </td></tr>
      
      <input type=hidden name=complaintid value=<%=(registerno+ 1)%><%=complaintID%>>
	  <input type=hidden name=complaintdate value=<%=currentdate1%>>
	  <input type=hidden name=complainttime value=<%=currenttime%>>
	  <input type=hidden name=groupcount value=<%=groupcount%>>	
	     
     </table>     
   </form>     
    </table>   

</body>